package com.ahuzdw.com.node;

/**
 * Author: Zhang Dongwei
 * Date: 2021/12/26 21:13
 */
public class MainDemo {
    public static void main(String[] args) {
        Node node = new MainDemo().new Node();
        node.data = 10;

//        Node1 node1 = new Node1(10);
//        Node1 node2 = new Node1();
//        node2.data = 3;

//        链表
        MyLinkedList list = new MainDemo().new MyLinkedList();
        list.add(10);
        list.add(3);
        list.add(5);
        list.add(9);
        list.add(7);
        list.display();
    }
    public class Node {
        public int data;
        public Node next = null;
    }

    public static class Node1 {
        public int data;
        public Node1 next = null;

//        默认构造
        public Node1(){

        }
        public Node1(int value){
            this.data = value;
        }
    }
    public class MyLinkedList{
        private Node1 first = null;
        private Node1 current = null;

//        在MyLinkedList对象中添加元素
        public void add(int value){
//            产生一个新的节点
            Node1 newNode = new Node1(value);
//            如果没有任何节点存在（第一个节点）
            if(first == null) {
                first = newNode;
                current = newNode;
            }else {
//            如果不是第一个节点
                current.next = newNode;
                current = newNode;
//                System.out.println("current"+current.data);
            }

        }
//        在控制台显示数据
        public void display() {
            Node1 node = first;
            while (node != null) {
                int value = node.data;
                System.out.println(value);
                node = node.next;
            }
        }
    }
}

